'use strict'

const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
config.entry.unshift(
  'babel-polyfill',   //热更新组件状态保存
  'react-hot-loader/patch',   //热更新组件状态保存
  'webpack-dev-server/client?http://localhost:3000',    //热更新添加
  'webpack/hot/only-dev-server'    //热更新添加
)
const webpack = require('webpack');
const path = require('path');
const compiler = webpack(config);
const server = new WebpackDevServer(compiler, {
  contentBase: path.resolve(__dirname, './dist'), //默认会以根文件夹提供本地服务器，这里指定文件夹
  inline: true, // 自动刷新
  hot: true, // 开启热模块替换
  historyApiFallback: true, //在开发单页应用时非常有用，它依赖于HTML5 history API，如果设置为true，所有的跳转将指向index.html
  port: 3000, //如果省略，默认8080
  host: '0,0,0,0'||'localhost',
  publicPath: "/",
  proxy: {
    '/api': {
      target: 'https://www.xxx.com',    //接口域名
      changeOrigin: true,      //接口跨域则需要改配置参数
      secure: false            //如果是https接口则需要配置该参数
    }
  }
});
server.listen(3000, server.host, function (err) {
  if (err) throw err
})